package edu.chl.da.ejb.core;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Embeddable;

/**
 * This class is the primary key for a flight.
 * @author Jakob
 */
@Embeddable
public class FlightPK implements Serializable {
    @Basic(optional = false)
    @Column(name = "FROMAIRPORT")
    private String fromairport;
    @Basic(optional = false)
    @Column(name = "FROMDESTINATION")
    private String fromdestination;
    @Basic(optional = false)
    @Column(name = "AIRPLANE")
    private int airplane;

    public FlightPK() {
    }

    public FlightPK(String fromairport, String fromdestination, int airplane) {
        this.fromairport = fromairport;
        this.fromdestination = fromdestination;
        this.airplane = airplane;
    }

    public String getFromairport() {
        return fromairport;
    }

    public void setFromairport(String fromairport) {
        this.fromairport = fromairport;
    }

    public String getFromdestination() {
        return fromdestination;
    }

    public void setFromdestination(String fromdestination) {
        this.fromdestination = fromdestination;
    }

    public int getAirplane() {
        return airplane;
    }

    public void setAirplane(int airplane) {
        this.airplane = airplane;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (fromairport != null ? fromairport.hashCode() : 0);
        hash += (fromdestination != null ? fromdestination.hashCode() : 0);
        hash += (int) airplane;
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof FlightPK)) {
            return false;
        }
        FlightPK other = (FlightPK) object;
        if ((this.fromairport == null && other.fromairport != null) || (this.fromairport != null && !this.fromairport.equals(other.fromairport))) {
            return false;
        }
        if ((this.fromdestination == null && other.fromdestination != null) || (this.fromdestination != null && !this.fromdestination.equals(other.fromdestination))) {
            return false;
        }
        if (this.airplane != other.airplane) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "edu.chl.da.ejb.core.FlightPK[fromairport=" + fromairport + ", fromdestination=" + fromdestination + ", airplane=" + airplane + "]";
    }

}
